package com.matrix;


import java.util.Scanner;

/**
 * 矩阵得分
 */
public class MatrixMain {

    /**
     * 按照需求中的方式录入数据
     * @param args
     */
    public static void main(String[] args) {
        //创建对象
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入矩阵的行列:");

        //多行输入
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] arr2 = new int[n][m];

        //可以直接读入
        for(int i=0; i<n; i++) {
            for(int j=0; j<m; j++) {
                arr2[i][j] = sc.nextInt();
            }
        }
        sc.close();

        // 放开注释测试
        // int[][] arr2 = {{0, 1, 0, 0}, {1, 0, 1, 0}};

        int sum = 0;
        for (int i = 0; i < arr2.length; i++) {
            for (int j = 0; j < arr2[i].length; j++) {
                if (1== arr2[i][j]) {
                    continue;
                }

                // 前遍历
                int front = 0;
                for (int x = 0; x < j; x++) {
                    front = front + arr2[i][x];
                }
                if (front>0) {
                    sum++;
                }

                // 后遍历
                int back = 0;
                for (int y = j; y < arr2[i].length; y++) {
                    back = back + arr2[i][y];
                }
                if (back>0) {
                    sum++;
                }

                // 上遍历
                int up = 0;
                for (int z = 0; z < i; z++) {
                    up = up + arr2[z][j];
                }
                if (up >0) {
                    sum++;
                }

                // 下遍历
                int down = 0;
                for (int d = i; d < arr2.length; d++) {
                    down = down + arr2[d][j];
                }
                if (down>0) {
                    sum++;
                }
            }
        }
        System.out.println(sum);


    }
}
